<template>
  <div>
    <div v-if="isLoaded">
      <div class="items">
        <img :src="img" :alt="title">
        <ul>
          <li><span class="label">名称:</span>{{title}}</li>
          <li><span class="label">导演:</span>{{directors}}</li>
          <li><span class="label">主演:</span>{{casts}}</li>
          <li><span class="label">类型:</span>{{genres}}</li>
          <li><span class="label">制片国家:</span>{{countries}}</li>
          <li><span class="label">上映日期:</span>{{pubdates}}</li>
          <li><span class="label">又名:</span>{{aka}}</li>
        </ul>
      </div>
      <div class="summary">
        <p><span class="label">简介:</span>{{summary}}</p>
      </div>
    </div>
    <loading :show="!isLoaded"></loading>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import * as types from '@/store/types'
import Loading from '@/components/loading'

export default {
  components: { Loading },
  computed: mapState({
    isLoaded: state => !state.movie.initing,
    title: state => state.movie.detail.title,
    img: state => state.movie.detail.img,
    directors: state => state.movie.detail.directors,
    writers: state => state.movie.detail.writers,
    casts: state => state.movie.detail.casts,
    genres: state => state.movie.detail.genres,
    countries: state => state.movie.detail.countries,
    languages: state => state.movie.detail.languages,
    pubdates: state => state.movie.detail.pubdates,
    durations: state => state.movie.detail.durations,
    aka: state => state.movie.detail.aka,
    summary: state => state.movie.detail.summary
  }),
  created () {
    this.fetchData()
  },
  watch: {
    '$route': 'fetchData'
  },
  methods: {
    fetchData () {
      this.$store.dispatch({
        type: types.FETCH_DETAIL,
        id: this.$route.params.id
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .items {
    display: flex;
    align-items: flex-start;

    img {
      width: 200px;
    }

    ul {
      margin: 0 0 0 10px;
      padding: 0;
      text-align: left;
      list-style: none;
    }
  }

  .label {
    color: gray;
  }

  .summary {
    p {
      text-align: left;
    }
  }
</style>
